package com.regvision.contacts.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexValidateUtil {
	
	/**
	 * 楠岃瘉閭
	 * 
	 * @param email
	 * @return
	 */
	public static boolean checkEmail(String email) {

		String check = "^([a-z0-9A-Z]+[-|_|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		return check(check, email);
	}

	/**
	 * 楠岃瘉鎵嬫満鍙风爜
	 * 
	 * @param mobiles
	 * @return
	 */
	public static boolean checkMobileNumber(String mobileNumber) {
		
		String check = "^(((13[0-9])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8})|(0\\d{2}-\\d{8})|(0\\d{3}-\\d{7})$";
		return check(check, mobileNumber);
	}
	
	/**
	 * 楠岃瘉鏄惁鏄�26鑻辨枃瀛楁瘝
	 * @param str
	 * @return
	 */
	public static boolean checkChar(String str) {

		String check = "^[A-Za-z]+$";
		return check(check, str);
	}
	
	public static boolean check(String check, String str) {
		boolean flag = false;
		try {
			Pattern regex = Pattern.compile(check);
			Matcher matcher = regex.matcher(str);
			flag = matcher.matches();
		} catch (Exception e) {
			e.printStackTrace();
			flag = false;
		}
		return flag;
	}
}
